import request from "@/utils/request";

/**
 * 获取系统菜单列表
 * @returns {Promise<List<MenuVO>} 返回菜单数据
 */
export function getMenuList(searchForm) {
  return request({
    url: "/menu",
    method: "get",
    params: searchForm,
  });
}

/**
 * 获取当前用户的菜单列表
 */
export function getCurrentUserMenuList() {
  return request({
    url: "/menu/current",
    method: "get",
  });
}

/**
 * 获取菜单树结构
 * @returns {Promise<Object>} 返回树形结构的菜单数据
 */
export function getMenuTree() {
  return request({
    url: "/menu/tree",
    method: "get",
  });
}

/**
 * 获取菜单详情
 * @param {number} id 菜单ID
 * @returns {Promise<Object>} 返回菜单详情
 */
export function getMenuDetail(id) {
  return request({
    url: `/menu/${id}`,
    method: "get",
  });
}

/**
 * 新增菜单
 * @param {Object} data 菜单数据
 * @returns {Promise<Object>} 返回操作结果
 */
export function addMenu(data) {
  return request({
    url: "/menu",
    method: "post",
    data,
  });
}

/**
 * 更新菜单
 * @param {Object} data 菜单数据
 * @returns {Promise<Object>} 返回操作结果
 */
export function updateMenu(data) {
  return request({
    url: `/menu`,
    method: "put",
    data,
  });
}

/**
 * 删除菜单
 * @param {number} id 菜单ID
 * @returns {Promise<Object>} 返回操作结果
 */
export function deleteMenu(param) {
  return request({
    url: `/menu/${param.type}/${param.id}`,
    method: "delete",
  });
}

// 导出
export default {
  getMenuList,
  getMenuTree,
  getCurrentUserMenuList,
  getMenuDetail,
  addMenu,
  updateMenu,
  deleteMenu,
};
